﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using YuuzleComic.DBUtility;
using System.Data;
using System.Data.SqlClient;
using Newtonsoft.Json.Linq;

public partial class support_chapter : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            JObject result = JObject.Parse("{s:0,p:0,n:0}");
            try
            {
                SqlParameter[] parameter = new SqlParameter[] { 
                    new SqlParameter("@id",Request["cid"]),
                    new SqlParameter("@cid",Request["bid"])
                };

                DataSet ds = DbHelperSQL.Query("select top(1) id from zj where ordernum>(select ordernum from zj where id=@id) and cid=@cid order by ordernum", parameter);
                if (ds.Tables[0].Rows.Count == 1)
                {
                    result["n"] = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
                }
                ds = DbHelperSQL.Query("select top(1) * from zj where ordernum<(select ordernum from zj where id=@id) and cid=@cid order by ordernum desc", parameter);
                if (ds.Tables[0].Rows.Count == 1)
                {
                    result["p"] = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
                }
                result["s"] = 1;
            }
            catch (Exception)
            {
            }
            if (Request["cb"] != null)
            {
                Response.Write(Request["cb"] + "(" + result.ToString() + ")");
            }
            else
            {
                Response.Write(result.ToString());
            }
        }

    }
}